﻿using System;
using System.Linq;
using IterationLife.FootballTeaching.Models;
using IterationLife.FootballTeaching.Repositories;
using Util;
using Util.Datas.Ef;

namespace IterationLife.Datas.Repositories.FootballTeachings
{
    /// <summary>
    /// 章节仓储
    /// </summary>
    public class ChapterRepository : RepositoryBase<Chapter>, IChapterRepository
    {
        /// <summary>
        /// 初始化章节仓储
        /// </summary>
        /// <param name="unitOfWork">工作单元</param>
        public ChapterRepository(IApplicationUnitOfWork unitOfWork) : base(unitOfWork)
        {
        }

        /// <summary>
        /// 获取排序号
        /// </summary>
        /// <param name="courseId">课程编号</param>
        public int GetSortId(Guid courseId)
        {
            return Find().Where(t => t.CourseId == courseId).Max(t => t.SortId).SafeValue() + 1;
        }
    }
}
